package lion.blog.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import lion.blog.model.BlogCatelog;
import lion.dev.lang.MapJ;
import lion.framework.core.web.ApplicationContext;

/**
 * 
 * 博客页面标题展示
 * <p>
 * 分为文章页，栏目页，其他页，不同显示
 * 
 * </p>
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年11月20日
 */
public class TitleTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {

		PageContext context = (PageContext) getJspContext();
		HttpServletRequest request = (HttpServletRequest) context.getRequest();

		MapJ article = (MapJ) request.getAttribute("article");
		MapJ setting = (MapJ) ApplicationContext.get("blog");

		// 文章页
		BlogCatelog catelog = null;

		if (article != null) {
			context.getOut().append(article.getString("title") + "-" + setting.getString("blogName"));
			return;
		}

		// 栏目页
		catelog = (BlogCatelog) request.getAttribute("catelog");
		if (catelog != null) {
			context.getOut().append(catelog.getName() + "-" + setting.getString("blogName"));
			return;
		}

		// 其他页面
		context.getOut().append(setting.getString("blogName"));
	}
}
